<?php
/**
 * Created by PhpStorm.
 * User: lhuan
 * Date: 2019/11/4
 * Time: 19:41
 */
namespace app\index\model;

use think\Model;

class PageInfo extends Model
{
    public $map = [];
    public $fields = '*';

    public function initialize()
    {
        parent::initialize();
    }

    public static function getPageInfo($id)
    {
        return PageInfo::find($id);
    }

    public static function getAllPage()
    {
        $data = PageInfo::where(['pid'=> 0])->order('id asc')->select();
        $data = data_trans($data);
//        $r = [];
        foreach($data as $k => $e)
        {
//            $r[] = [
//                'value' => $e['id'],
//                'label'=> $e['name'],
//            ];
            $son = PageInfo::where(['pid'=> $e['id']])->order('id asc')->select();
            if(!empty($son)){
                $data[$k]['son'] = $son;
                $son = data_trans($son);
//                foreach($son as $v){
//                    $r[$k]['children'][] = [
//                        'value' => $v['id'],
//                        'label' => $v['name']
//                    ];
//                }

            }
        }
        return $data;
    }

    public static function modify($data)
    {
        unset($data['create_time']);
        $data['update_time'] = date('Y-m-d H:m:s');
        return PageInfo::update($data);
    }
}